import { PrimaryGeneratedColumn, Column, JoinColumn, OneToOne, Entity } from 'typeorm';
import { User } from './user.entity';
import { ApiProperty } from '@nestjs/swagger';
import { IsOptional } from 'class-validator';

/** 用户信息表 */
@Entity()
export class Profile {
  @PrimaryGeneratedColumn({ comment: '唯一标识id' })
  id: number;

  @ApiProperty({ description: '昵称' })
  @IsOptional()
  @Column({ nullable: true, comment: '昵称' })
  nickName: string;

  @ApiProperty({ description: '性别 0 男 1 女' })
  @IsOptional()
  @Column({ nullable: true, comment: '性别 0 男 1 女' })
  gender: number;

  @ApiProperty({ description: '头像' })
  @IsOptional()
  @Column({
    comment: '头像',
    default: 'https://avatars.githubusercontent.com/u/76676473?s=400&u=73c8c02de1dc39ba80aec1b7a366dffc67509bbb&v=4',
  })
  avatar: string;

  @ApiProperty({ description: '地址' })
  @IsOptional()
  @Column({ nullable: true, comment: '地址' })
  address: string;

  @ApiProperty({ description: '邮箱' })
  @IsOptional()
  @Column({ nullable: true, comment: '邮箱' })
  email: string;

  @OneToOne(() => User, (user) => user.profile, {
    createForeignKeyConstraints: false, //创建一个外键
    onDelete: 'CASCADE', //指定删除父表数据时的约束行为 CASCADE 级联 删除更新父表会级联到子表
  })
  @JoinColumn()
  user: User;

  @Column({ comment: '用户id' })
  userId: number;
}
